package acwing._1_1AlgorithmBasic._6Greedy;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._1_1AlgorithmBasic._6Greedy
 * @File : Q0906.java
 * @Author : WangRuoyu
 * @Date : 2023/4/7 9:26
 */

import java.io.*;
import java.util.Arrays;

public class Q0906 {
    static boolean check(int l, int r, int cnt, int[] g) {
        for (int i = 0; i < cnt; ++i) {
            if (g[i] < l) {
                g[i] = r;
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] words = br.readLine().split(" ");
        int n = Integer.parseInt(words[0]);
        int[][] s = new int[n][2];
        for (int i = 0; i < n; ++i) {
            words = br.readLine().split(" ");
            int l = Integer.parseInt(words[0]);
            int r = Integer.parseInt(words[1]);
            s[i][0] = l;
            s[i][1] = r;
        }
        Arrays.sort(s, (o1, o2) -> o1[0] != o2[0] ? o1[0] - o2[0] : o1[1] - o2[1]);

        int cnt = 0;
        int[] g = new int[n];
        for (int i = 0; i < n; ++i) {
            if (cnt == 0 || !check(s[i][0], s[i][1], cnt, g)) {
                g[cnt] = s[i][1];
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}
